package com.knowledge.graph.exception;

import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.resource.ResourceHttpRequestHandler;

import javax.servlet.http.HttpServletRequest;
import java.nio.file.Path;

/**
 * @author jiwenlong
 * @version 1.0
 * @description: 处理视频对象
 * @date 2023/11/23 17:20
 */
@Component
public class NonStaticResourceHttpRequestHandler extends ResourceHttpRequestHandler {
    @Override
    protected Resource getResource(HttpServletRequest request) {
        // 获取视频路径对象
        Path filePath = (Path) request.getAttribute("video");
        // 用 FileSystemResource 加载资源
        return new FileSystemResource(filePath);
    }
}
